home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / Kubuntu 8.10 / kubuntu-8.10-desktop-i386.iso / casper / filesystem.squashfs / usr / share / hplip / ui / chooseprinterdlg.py < prev    next >
Text File  |  2008-10-13  |  7KB  |  191 lines

  1. # -*- coding: utf-8 -*-
  2. #
  3. # (c) Copyright 2001-2007 Hewlett-Packard Development Company, L.P.
  4. #
  5. # This program is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; either version 2 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
  18. #
  19. # Author: Don Welch
  20. #
  21.  
  22. from base.g import *
  23. from base import device
  24. import sys
  25. from qt import *
  26.  
  27. class ChoosePrinterDlg(QDialog):
  28.     def __init__(self, printers, back_end_filter=['hp'], parent = None,name = None,modal = 0,fl = 0, show_uris=True):
  29.         QDialog.__init__(self,parent,name,modal,fl)
  30.  
  31.         if not name:
  32.             self.setName("ChooseDeviceDlg")
  33.  
  34.         self.device_uri = ''
  35.         self.back_end_filter = back_end_filter
  36.  
  37.         ChooseDeviceDlg_Layout = QGridLayout(self,1,1,6,6,"ChooseDeviceDlg_Layout")
  38.  
  39.         self.OKButton = QPushButton(self,"OKButton")
  40.  
  41.         ChooseDeviceDlg_Layout.addWidget(self.OKButton,2,2)
  42.  
  43.         self.CancelButton = QPushButton(self,"CancelButton")
  44.  
  45.         ChooseDeviceDlg_Layout.addWidget(self.CancelButton,2,1)
  46.         spacer1 = QSpacerItem(391,20,QSizePolicy.Expanding,QSizePolicy.Minimum)
  47.         ChooseDeviceDlg_Layout.addItem(spacer1,2,0)
  48.         spacer2 = QSpacerItem(20,290,QSizePolicy.Minimum,QSizePolicy.Expanding)
  49.         ChooseDeviceDlg_Layout.addItem(spacer2,1,0)
  50.  
  51.         self.DevicesButtonGroup = QButtonGroup(self,"DevicesButtonGroup")
  52.         self.DevicesButtonGroup.setColumnLayout(0,Qt.Vertical)
  53.         self.DevicesButtonGroup.layout().setSpacing(6)
  54.         self.DevicesButtonGroup.layout().setMargin(6)
  55.         DevicesButtonGroupLayout = QGridLayout(self.DevicesButtonGroup.layout())
  56.         DevicesButtonGroupLayout.setAlignment(Qt.AlignTop)
  57.  
  58.         self.radio_buttons = {}
  59.  
  60.         self.printer_index, x = {}, 0
  61.         for p in printers:
  62.             try:
  63.                 back_end, is_hp, bus, model, serial, dev_file, host, port = \
  64.                     device.parseDeviceURI(p.device_uri)
  65.  
  66.             except Error:
  67.                 continue
  68.  
  69.             if back_end in back_end_filter:
  70.                 self.printer_index[x] = (p.name, p.device_uri)
  71.                 x += 1
  72.  
  73.  
  74.         for y in range(len(self.printer_index)):
  75.             if y == 0:
  76.                 self.device_uri = self.printer_index[y][1]
  77.  
  78.             self.radio_buttons[y] = QRadioButton(self.DevicesButtonGroup,"radioButton%d" % y)
  79.  
  80.             if show_uris:
  81.                 self.radio_buttons[y].setText("%s  (%s)" % self.printer_index[y])
  82.             else:
  83.                 self.radio_buttons[y].setText(self.printer_index[y])
  84.  
  85.             DevicesButtonGroupLayout.addWidget(self.radio_buttons[y], y, 0)
  86.  
  87.         self.radio_buttons[0].setChecked(1)
  88.  
  89.         ChooseDeviceDlg_Layout.addMultiCellWidget(self.DevicesButtonGroup,0,0,0,2)
  90.  
  91.         self.languageChange()
  92.  
  93.         self.resize(QSize(592,112).expandedTo(self.minimumSizeHint()))
  94.         self.clearWState(Qt.WState_Polished)
  95.  
  96.         self.connect(self.OKButton,SIGNAL("clicked()"),self,SLOT("accept()"))
  97.         self.connect(self.CancelButton,SIGNAL("clicked()"),self,SLOT("reject()"))
  98.         self.connect(self.DevicesButtonGroup,SIGNAL("clicked(int)"),self.DevicesButtonGroup_clicked)
  99.  
  100.     def languageChange(self):
  101.         self.setCaption(self.__tr("Choose Device"))
  102.         self.OKButton.setText(self.__tr("OK"))
  103.         self.CancelButton.setText(self.__tr("Cancel"))
  104.  
  105.         if 'hp' in self.back_end_filter and 'hpfax' in self.back_end_filter:
  106.             self.DevicesButtonGroup.setTitle(self.__tr("Available Devices:"))
  107.         elif 'hp' in self.back_end_filter:
  108.             self.DevicesButtonGroup.setTitle(self.__tr("Available Printers:"))
  109.         elif 'hpfax' in self.back_end_filter:
  110.             self.DevicesButtonGroup.setTitle(self.__tr("Available Faxes:"))
  111.         else:
  112.             self.DevicesButtonGroup.setTitle(self.__tr("Available Devices:"))
  113.  
  114.     def __tr(self,s,c = None):
  115.         return qApp.translate("ChooseDeviceDlg",s,c)
  116.  
  117.     def DevicesButtonGroup_clicked(self,a0):
  118.         for p in self.printer_index:
  119.             pp = self.printer_index[p]
  120.             if unicode(self.radio_buttons[a0].text()).startswith(pp[0]):
  121.                 self.device_uri = pp[1]
  122.                 break
  123.  
  124.  
  125.  
  126. class ChoosePrinterDlg2(QDialog):
  127.     def __init__(self, printers, parent = None,name = None,modal = 0,fl = 0):
  128.         QDialog.__init__(self,parent,name,modal,fl)
  129.  
  130.         self.printers = printers
  131.  
  132.         if not name:
  133.             self.setName("ChooseDeviceDlg2")
  134.  
  135.         ChooseDeviceDlg_Layout = QGridLayout(self,1,1,6,6,"ChooseDeviceDlg_Layout")
  136.  
  137.         self.OKButton = QPushButton(self,"OKButton")
  138.  
  139.         ChooseDeviceDlg_Layout.addWidget(self.OKButton,2,2)
  140.  
  141.         self.CancelButton = QPushButton(self,"CancelButton")
  142.  
  143.         ChooseDeviceDlg_Layout.addWidget(self.CancelButton,2,1)
  144.         spacer1 = QSpacerItem(391,20,QSizePolicy.Expanding,QSizePolicy.Minimum)
  145.         ChooseDeviceDlg_Layout.addItem(spacer1,2,0)
  146.         spacer2 = QSpacerItem(20,290,QSizePolicy.Minimum,QSizePolicy.Expanding)
  147.         ChooseDeviceDlg_Layout.addItem(spacer2,1,0)
  148.  
  149.         self.DevicesButtonGroup = QButtonGroup(self,"DevicesButtonGroup")
  150.         self.DevicesButtonGroup.setColumnLayout(0,Qt.Vertical)
  151.         self.DevicesButtonGroup.layout().setSpacing(6)
  152.         self.DevicesButtonGroup.layout().setMargin(6)
  153.         DevicesButtonGroupLayout = QGridLayout(self.DevicesButtonGroup.layout())
  154.         DevicesButtonGroupLayout.setAlignment(Qt.AlignTop)
  155.  
  156.         self.radio_buttons = {}
  157.  
  158.         for y in range(len(self.printers)):
  159.             if y == 0:
  160.                 self.printer_name = self.printers[0]
  161.  
  162.             self.radio_buttons[y] = QRadioButton(self.DevicesButtonGroup,"radioButton%d" % y)
  163.             self.radio_buttons[y].setText(self.printers[y])
  164.             DevicesButtonGroupLayout.addWidget(self.radio_buttons[y], y, 0)
  165.  
  166.         self.radio_buttons[0].setChecked(1)
  167.  
  168.         ChooseDeviceDlg_Layout.addMultiCellWidget(self.DevicesButtonGroup,0,0,0,2)
  169.  
  170.         self.languageChange()
  171.  
  172.         self.resize(QSize(592,112).expandedTo(self.minimumSizeHint()))
  173.         self.clearWState(Qt.WState_Polished)
  174.  
  175.         self.connect(self.OKButton,SIGNAL("clicked()"),self,SLOT("accept()"))
  176.         self.connect(self.CancelButton,SIGNAL("clicked()"),self,SLOT("reject()"))
  177.         self.connect(self.DevicesButtonGroup,SIGNAL("clicked(int)"),self.DevicesButtonGroup_clicked)
  178.  
  179.     def languageChange(self):
  180.         self.setCaption(self.__tr("Choose Printer"))
  181.         self.OKButton.setText(self.__tr("OK"))
  182.         self.CancelButton.setText(self.__tr("Cancel"))
  183.  
  184.         self.DevicesButtonGroup.setTitle(self.__tr("Printers:"))
  185.  
  186.     def __tr(self,s,c = None):
  187.         return qApp.translate("ChooseDeviceDlg2",s,c)
  188.  
  189.     def DevicesButtonGroup_clicked(self,a0):
  190.         self.printer_name = self.printers[a0]
  191.